//
//  UIImage+FTImage.m
//  飞天FM
//
//  Created by Song on 2017/6/11.
//  Copyright © 2017年 SongZhaoJun. All rights reserved.
//  UIImage分类

#import "UIImage+FTImage.h"

@implementation UIImage (FTImage)

+(UIImage *)originImageWithName:(NSString *)name{
    
    return [[UIImage imageNamed:name] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}


-(UIImage *)circleImage {
    
    // 获取图片Size
    CGSize size = self.size;
    
    //创建要街区的Size（最终要显示的区域）
    CGFloat sizeWH = size.width < size.height ? size.width : size.height;
    
    // 1.创建图形上下文
    UIGraphicsBeginImageContext(size);
    
    // 2.绘制圆形，进行裁剪
    CGContextRef contexRf = UIGraphicsGetCurrentContext();
    // 创建剪切的区域
    CGRect clickRect = CGRectMake(0, 0, sizeWH, sizeWH);
    // 绘制图形(绘制一个圆形)
    CGContextAddEllipseInRect(contexRf, clickRect);
    //剪切
    CGContextClip(contexRf);
    
    // 3.绘制大图片(按照原本此村进行裁剪)
    // 绘制区域
    CGRect imageRect = CGRectMake(0, 0, size.width, size.height);
    [self drawInRect:imageRect];
    
    // 4.获取图片
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    
    //5.关闭上下文
    UIGraphicsEndImageContext();
    
    return image;
    
}


@end
